using System;
using System.Linq;
using Churchtoolkit.DataAccess.Common;

namespace Churchtoolkit
{
    public static class RepositoryExtentions
    {
        public static TEntity Single<TEntity, TEnum>(this ReadOnlyRepositoryBase<TEntity, TEnum> repository,
            Action<TEntity> expression, TEnum? orderByColumn, int? startIndex, int? endIndex
            )
            where TEntity : IEntity, new()
            where TEnum : struct
        {
            return repository.Find(expression, orderByColumn, startIndex, endIndex).Single();
        }
        public static TEntity Single<TEntity, TEnum>(this ReadOnlyRepositoryBase<TEntity, TEnum> repository,
           Action<TEntity> expression, TEnum orderByColumn)
            where TEntity : IEntity, new()
            where TEnum : struct
        {
            return repository.Find(expression, orderByColumn).Single();
        }

        public static TEntity Single<TEntity, TEnum>(this ReadOnlyRepositoryBase<TEntity, TEnum> repository,
          Action<TEntity> expression)
            where TEntity : IEntity, new()
            where TEnum : struct
        {
            return repository.Find(expression).Single();
        }
    }
}